package com.xd.demo.controller;

import com.alibaba.fastjson.JSON;
import com.xd.demo.aspect.CryptoAnnotation;
import com.xd.demo.constant.EducationType;
import com.xd.demo.constant.MarriageStatus;
import com.xd.demo.dto.*;
import com.xd.demo.model.Individual;
import org.springframework.web.bind.annotation.*;

@RestController
public class HelloWorld {

    @RequestMapping(value = "/hello",method = RequestMethod.POST)
    public String hello(@RequestBody String name){
        System.out.println(name);
        return "hello "+ name;
    }

    @RequestMapping(value = "/hellox",method = RequestMethod.GET)
    public String helloXie(String name){
        return "hello "+name+", from xiedi";
    }



    @CryptoAnnotation(model = "JD",operation = "jd_credit")
    @RequestMapping(value = "/credit",method = RequestMethod.POST)
    public JdResDto test_credit(@RequestBody ReqDto<JdCreditApplyReqDto> params){
        System.out.println(JSON.toJSONString(params));
        JdResDto jdResDto = new JdResDto();
        jdResDto.setCode("0000");
        jdResDto.setMsg("成功");
        jdResDto.setResponseData("需要加密的数据");
        jdResDto.setSysSign("xiedi");
        return jdResDto;

    }


    /**
     * 本地赋值尚未完成
     * @param reqDto
     * @return
     */
    private Individual transChanelData(JdCreditApplyReqDto reqDto){
        Individual individual = new Individual();
        JdUserInfo userInfo = reqDto.getUserInfo();


        individual.setName(userInfo.getUserName());
        individual.setCertNo(userInfo.getCertNo());
        individual.setChannel(reqDto.getCreditMode());
        individual.setMobile(userInfo.getUserTel());
        individual.setAddress(userInfo.getAddress());
        individual.setNation(null);
        individual.setGender(null);
        individual.setValidFrom(null);// 有效期开始
        individual.setValidTo(null);// TODO 有效期结束,我们只有结束日期，需要计算 起始日期
        individual.setAddress(userInfo.getAddress());
        individual.setEducation(EducationType.UNKNOWN.getCode());
        individual.setMarriage(MarriageStatus.UNKNOWN.getCode());

        IndividualDto individualDto = null;
//        individualService.save(individual);
//        WorkInfo workInfo = new WorkInfo();
//        workInfo.setCorpName();
//        individualContactsService.save(individual, individualDto.getContact());
//
//
//        individualWorkService.save(individual, workInfo);

        return individual;

    }



}
